#pragma once

#define RENAME_EXT_DEFAULT 12
#define RENAME_FILE_DEFAULT 6

class FilesRenamer : protected FilerFrogElement
{
private:
	list<wstring> m_filesList;
	int RenameToTempNames();
	int PerformRename();
protected:
	list<wstring> m_newNames;
	list<wstring> m_tmpNames;
	list<wstring> m_orgNames;

	virtual int GenerateNewNames() = 0;
	int CheckBlackList(const list<wstring>& blackList, int fail);
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName) = 0;
public:
	explicit
	FilesRenamer(HWND parent, const std::list<wstring> &filesList);

	void Rename(FRRESPONSE& res);
};

// renames files with a find/replace mechanism
class FilesRenamerFindReplace : public FilesRenamer
{
private:
	wstring m_search;
	wstring m_replace;
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
public:
	explicit
	FilesRenamerFindReplace(HWND parent, const std::list<wstring> &filesList, 
		const wstring& search, const wstring& replace);
};


// renames files with autonumbering
class FilesRenamerAutonumbering : public FilesRenamer
{
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
	int count;
	list<int> m_exceptions;
public:
	explicit
	FilesRenamerAutonumbering(HWND parent, const std::list<wstring> &filesList, int start);
};

// renames files with autonumbering
class FilesRenamerAlphabetize : public FilesRenamer
{
private:
	WCHAR FIRST_CHAR;
	WCHAR LAST_CHAR;
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
	WCHAR m_char;
	void advanceChar();
	int m_count;
public:
	explicit
	FilesRenamerAlphabetize(HWND parent, const std::list<wstring> &filesList);
};


// renames files appends prefix and postfix
class FilesRenamerAppend : public FilesRenamer
{
private:
	wstring m_prefix;
	wstring m_postfix;
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
public:
	explicit
	FilesRenamerAppend(HWND parent, const std::list<wstring> &filesList, 
		const wstring& prefix, const wstring& postfix);
};

// rename files alphebtize & append prefix/postfix
class FilesRenamerAlphabetizeAppend : public FilesRenamerAlphabetize
{
private:
	wstring m_prefix;
	wstring m_postfix;
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
public:
	explicit
	FilesRenamerAlphabetizeAppend(HWND parent, const std::list<wstring> &filesList, 
		const wstring& prefix, const wstring& postfix);
};

// rename files autonumber & append prefix/postfix
class FilesRenamerAutonumberAppend : public FilesRenamerAutonumbering
{
private:
	wstring m_prefix;
	wstring m_postfix;
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
public:
	explicit
	FilesRenamerAutonumberAppend(HWND parent, const std::list<wstring> &filesList, int start,
		const wstring& prefix, const wstring& postfix);
};

// rename files make them all with the same name (except extension)
class FilesRenamerMakeSameName : public FilesRenamer
{
private:
	wstring m_anchor; // this is anchor full path!
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
public:
	explicit
	FilesRenamerMakeSameName(HWND parent, const std::list<wstring> &filesList, const wstring& anchor);
};

// rename files truncate first or last characters (with or without extension)
class FilesRenamerTruncate : public FilesRenamer
{
private:
	int m_numberOfChars;
	bool m_truncFromBegining;
	bool m_includeFileExtension;
protected:
	virtual int GenerateNewNames();
	//virtual bool renameFile(const wstring& fileName, const wstring& actFileName);
public:
	explicit
		FilesRenamerTruncate(HWND parent, const std::list<wstring> &filesList, int numberOfChars, 
		bool truncFromBegining, bool includeFileExtension);
};
